//
//  UITableViewCell+OF.m
//  HMmall
//
//  Created by 李李善 on 16/6/25.
//  Copyright © 2016年 吉青. All rights reserved.
//

#import "UITableViewCell+OF.h"
#import <objc/runtime.h>
#import "UIView+Base.h"
const char * kPushedViewController;




const char * kCellClick;

@implementation UITableViewCell (OF)


- (UIViewController *)pushedViewController
{
    return objc_getAssociatedObject(self, kPushedViewController);
}


- (void)setPushedViewController:(UIViewController *)pushedViewController
{
    objc_setAssociatedObject(self, kPushedViewController, pushedViewController, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (void)update:(id)model forTableView:(UITableView *)tableView AtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(void)onTextForBlock:(void (^)(NSString *, id, id, NSIndexPath *, id))blcok
{
    if (self.textBlcok != blcok) {
        self.textBlcok = blcok;
    }
}


- (void)onButtonForBlock:(void (^)(id, id, NSIndexPath *, id))blcok
{
    if (self.buttonBlcok != blcok) {
        self.buttonBlcok = blcok;
    }
}

- (void)onCellForBlock:(void (^)(UITableViewCell *, NSIndexPath *, id))blcok
{
    if (self.cellBlcok != blcok) {
        self.cellBlcok = blcok;
    }
    
}

-(void)setCellBlcok:(void (^)(UITableViewCell *, NSIndexPath *, id))cellBlcok
{
    objc_setAssociatedObject(self, &kCellClick,cellBlcok, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
}
-(void (^)(UITableViewCell *, NSIndexPath *, id))cellBlcok
{
    return  objc_getAssociatedObject(self, &kCellClick);
}







@end


@implementation UIView (Cell)

- (UITableViewCell *)findTableViewCell
{
    UITableViewCell *c = (id)self.superview;
    int i = 0;
    while (![c isKindOfClass:[UITableViewCell class]]) {
        c = (id)c.superview;
        if (i==10){return nil;}
        i++;
    }
    return c;

}

- (UITableViewHeaderFooterView *)findHeaderFooderView
{
    UITableViewHeaderFooterView *c = (id)self.superview;
    int i = 0;
    while (![c isKindOfClass:[UITableViewHeaderFooterView class]]) {
        c = (id)c.superview;
        if (i==10){return nil;}
        i++;
    }
    return c;

}


@end
